package view;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.tables.Column;
import org.uqbar.arena.widgets.tables.Table;
import org.uqbar.arena.windows.SimpleWindow;
import org.uqbar.arena.windows.Window;
import org.uqbar.arena.windows.WindowOwner;

import usuario.Usuario;
import asiento.Asiento;
import controller.DateFormaterTransformer;

public abstract class ListadoAsientosWindow extends Window<Usuario> {
	
	public ListadoAsientosWindow(WindowOwner owner, Usuario usuario) {
		super(owner, usuario);
	}


	public void createContents(Panel mainPanel) {
		
		this.setTitle(AterrizarWindow.getTituloAplicacion());
		new Label(mainPanel).setText(this.getLabelText());
		this.createResultsGrid(mainPanel);
		this.createActionsPanel(mainPanel);
	}

	protected abstract String getLabelText();

	private void createResultsGrid(Panel mainPanel) {
		Table<Asiento> table = new Table<Asiento>(mainPanel, Asiento.class);
		table.setHeigth(200);
		table.setWidth(600);

		this.bindearItemsATabla(table);

		this.describeResultsGrid(table);
	}

	protected abstract void bindearItemsATabla(Table<Asiento> table);
	
	private void describeResultsGrid(Table<Asiento> table) {
		new Column<Asiento>(table) //
		.setTitle("Salida")
		.setFixedSize(100)
		.bindContentsToProperty("fechaSalida")
		.bindContentsToTransformer(new DateFormaterTransformer());

		new Column<Asiento>(table) //
		.setTitle("Aerolinea")
		.setFixedSize(100)
		.bindContentsToProperty("aerolinea");

		new Column<Asiento>(table)//
		.setTitle("Vuelo")
		.setFixedSize(100)
		.bindContentsToProperty("vuelo");
		
		new Column<Asiento>(table)//
		.setTitle("N� Asiento")
		.setFixedSize(100)
		.bindContentsToProperty("numeroAsiento");

		new Column<Asiento>(table)//
		.setTitle("Precio")
		.setFixedSize(100)
		.bindContentsToProperty("precio");
	
	}

	protected void createActionsPanel(Panel mainPanel) {
		Panel actionsPanel = new Panel(mainPanel);
		actionsPanel.setLayout(new HorizontalLayout());
		this.addActions(actionsPanel);
	}
	
	protected void addActions(Panel actionsPanel) {
		
		new Button(actionsPanel)//
		.setCaption("Cancelar")
		.onClick(new MessageSend(this, "close"));
		
	}




}
